
#include <atomic>


atomic<int>  dd = 0;
void fun1()
{
	for (int i =0 ; i<100; i++)
	{
		int pos = dd.load(memory_order_acquire);
		//dd.compare_exchange_strong(pos, pos + 1, memory_order_acquire);
		
	//	wdd.compare_exchange_strong(pos,pos+1,memory_order_acquire)  strong 应该是只返回true
		while (!dd.compare_exchange_weak(pos, pos + 1, memory_order_acquire));// 反复测试 直到返回true
	}

}


<atomic> 的compare_exchange_weak 和 __sync_bool_compare_and_swap 有什么区别 https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html#:~:text=type%20__sync_val_compare_and_swap%20%28type%20%2Aptr%2C%20type%20oldval%2C%20type%20newval%2C...%29,the%20comparison%20is%20successful%20and%20newval%20is%20written.
atomic的跨平台 后者是gcc下的builtin fun